package com.dark.twitter;

import twitter4j.*;
import twitter4j.api.FriendsFollowersResources;

import java.util.List;

/**
 * Created by tengxue on 16-4-19.
 */
public class TwitterTest {
    public static void main(String[] args)throws Exception{
        Twitter twitter = TwitterFactory.getSingleton();
        //获取首页消息
//        List<Status> statuses = twitter.getHomeTimeline();
//        System.out.println("Showing home timeline.");
//        System.out.println("获取到首页消息的条数是:"+statuses.size());
//        for (Status status : statuses) {
//            System.out.println("关注者的Name:"+status.getUser().getName());
//            System.out.println("关注者的ScreenName:"+status.getUser().getScreenName());
//            System.out.println("关注者的Lang:" + status.getUser().getLang());
//            System.out.println("关注者的ListedCount:" + status.getUser().getListedCount());
//            System.out.println(status.getUser().getName() + ":" +
//                    status.getText());
//        }

        //获取自己的id
        long myId= twitter.getId();
        //获取自己发送的消息
        List<Status> myStatuses=twitter.getUserTimeline(myId);
//        for (Status status : myStatuses) {
//            System.out.println("关注者的Name:"+status.getUser().getName());
//            System.out.println("关注者的ScreenName:"+status.getUser().getScreenName());
//            System.out.println("关注者的Lang:" + status.getUser().getLang());
//            System.out.println("关注者的ListedCount:" + status.getUser().getListedCount());
//            System.out.println(status.getUser().getName() + ":" +
//                    status.getText());
//
//
//        }


        long followerCursor = -1;
        //我关注中的用户id
        IDs myFriends=twitter.getFriendsIDs(myId, followerCursor);
        long[] myFriendsIds=myFriends.getIDs();
        System.out.println("关注中用户的数量是 :"+myFriendsIds.length);

        for (long id :myFriendsIds){
            System.out.println("the id is:" + id);
            ResponseList<User> friends = twitter.lookupUsers(id);
            for(User friend : friends) {
                System.out.println("the id is:"+friend.getId());
                System.out.println("the name:"+friend.getName());
                System.out.println("the ScreenName is:"+friend.getScreenName());
                System.out.println("the Location is:" + friend.getLocation());
                System.out.println("the FollowersCount is:" + friend.getFollowersCount());
                System.out.println("the FriendsCount is:" + friend.getFriendsCount());
                System.out.println("-------------------------------------------------------------------------------------------");

                Paging paging=new Paging();
                paging.setPage(1);
                paging.setCount(10);

                List<Status> friendsStatuses=twitter.getUserTimeline(friend.getId(),paging);
                System.out.println("the friendsStatuses size:" + friend.getFriendsCount());
                //查看被关注者的发送的消息
                for (Status status : friendsStatuses) {
                    System.out.println("关注者首页接受的消息来源---------------->name:"+status.getUser().getName()+";ScreenName:"+status.getUser().getScreenName());
                    System.out.println("关注者首页接受的消息:" +status.getText());
                    System.out.println("关注者首页接受的消息:" + status.getInReplyToScreenName());


                }

            }


        }

        FriendsFollowersResources item=twitter.friendsFollowers();
        IDs ids=item.getFollowersIDs(myId, followerCursor);

        long[] followersIds=ids.getIDs();
        System.out.println("关注者的数量是 :"+followersIds.length);
        //遍历被关注人的信息
        for (long id:followersIds){
            System.out.println("the id is:"+id);
            ResponseList<User> followers = twitter.lookupUsers(id);

            for(User follower : followers) {
                System.out.println("the id is:"+follower.getId());
                System.out.println("the name:"+follower.getName());
                System.out.println("the ScreenName is:"+follower.getScreenName());
                System.out.println("the Location is:" + follower.getLocation());
                System.out.println("the FollowersCount is:" + follower.getFollowersCount());
                System.out.println("the FriendsCount is:" + follower.getFriendsCount());

                Paging paging=new Paging();
                paging.setPage(1);
                paging.setCount(10);

                List<Status> followerStatuses=twitter.getUserTimeline(paging);
                System.out.println("the friendsStatuses size:" + follower.getFriendsCount());
                //查看被关注者的发送的消息
                for (Status status : followerStatuses) {
                    System.out.println("关注者首页接受的消息来源---------------->name:"+status.getUser().getName()+";ScreenName:"+status.getUser().getScreenName());
                    System.out.println("关注者首页接受的消息:" +status.getText());
                    System.out.println("关注者首页接受的消息:" + status.getInReplyToScreenName());


                }

            }
            System.out.println("--------------------------------------------------------------------");
        }



    }

}
